<?php
init_timer();
include_once($relPath.'rounds.php');
include_once($relPath.'list_projects.inc');

$is_sidebar = false;

function DpHeader($pagetitle = "", $args = null) {

    global  $code_url, 
            $js_url, 
            $css_url, 
            $site_abbreviation,
            $site_name,
            $User;

    $jsfile  = @$args["jsfile"];
    $jstext  = @$args["jstext"];
    $cssfile = @$args["cssfile"];
    $csstext = @$args["csstext"];
    $onload  = @$args["onload"];

    echo
"<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<meta name='description' content='Distributed Proofreaders' />
<link rel='shortcut icon' href='$code_url/favicon.ico'>
<title>{$site_abbreviation}{$pagetitle}</title>
<link type='text/css' rel='stylesheet' href='{$css_url}/dp.css'>\n";

    echo (($cssfile && $cssfile != "")
        ? "<link type='text/css' rel='stylesheet'
                                    href='{$css_url}/{$cssfile}'>\n"
        : "");

    echo (($jsfile && $jsfile != "")
        ? "<script type='text/javascript' 
            src='{$js_url}/{$jsfile}' charset='utf-8'></script>\n"
        : "");

    echo (($jstext == "") 
        ? "" 
        : "<script type='text/javascript'>\n"
                   . $jstext 
                   . "\n</script>\n");

    echo (($csstext == "") 
        ? ""
        : "<style type='text/css'>\n"
                   . $csstext 
                   . "\n</style>\n");
    echo "</head>

<body"
    .($onload == "" 
        ? ">" 
        : " onload='$onload'>\n");

    echo "
<div id='logobar' class='logobar'>
  <div id='it-logo-left' class='it-logo'>
      <h3>Conserviamo la nostra storia<br/>una pagina per volta</h3>
  </div>
  <div id='it-logo-center' class='it-logo'>
 <img src='/graphics/dpit-logo.gif' class='logo' alt='$site_name'>
  </div>
  <div id='it-logo-right' class='it-logo'>
    <h4>xx libri salvati per tutti</h4>
  </div>
</div>  <!-- div#logobar -->\n";


    if(! $User->IsLoggedIn()) {
        echo "
    <div class='navbar'>
      <div class='navleft'>
        ".link_to_site()."
      </div> <!-- div.navleft -->
      <div id='login' class='navright'>
        <form id='login_form' accept-charset='UTF-8' method='post'>
          <span>Username:</span>&nbsp;
          <input class='navbar' type='text' name='userNM' 
                                    size='10' maxlength='50'>
          <span>Password:</span>&nbsp;
          <input type='password' name='userPW' size='10' maxlength='50'>
          <input type='submit' value='".h(_("Sign In"))."'>
          ".link_to_forums()."
          ".link_to_registration()."
          ".link_to_help()."
        </form>
      </div  <!-- div#login.navright -->>
    </div>  <!-- div.navbar -->\n";
    }
    else {
        echo "
      <div class='navbar'>
        <div class='navleft'>"

           ." | "
           .link_to_activity_hub()
           ."<span style='white-space: nowrap;'>["
           . ($User->IsProjectManager() 
                    ? link_to_projectmgr("PM")
                    : "")."\n"
           .link_to_task("proof")."\n"
           .link_to_task("reproof")."\n"
           .link_to_task("mark")."\n"
           .link_to_task("check")."\n"
           .link_to_task("special")."\n";

        echo ("]</span>"
            .link_to_my_projects()
            .link_to_project_search()
            .($User->MayManageRoles() ? link_to_rolemgr() : "")
            // .link_to_rolemgr()
            ."</div> <!-- navleft -->\n");

        // right side
        $prompt = ($User->InboxCount() > 0 
            ? sprintf(_("Inbox (%s)"), $User->InboxCount())
            : "Inbox");

        echo "<div class='navright'>
            ".link_to_inbox($prompt)
            .link_to_forums()
            .link_to_stats()
            .link_to_userprefs()
            .link_to_help()
            .link_to_logout()."
            ({$User->Username()})
            </div>
        </div> <!-- navbar -->\n";
    }
}

function DpFooter() {
    global $site_name;
    echo "
</div>   <!-- theme_body_div -->
<div class='footerbar'>
    ". _("Copyright")." $site_name
    ("._("Page Build Time").": ".get_timer().") 
</div>
</body>
</html>";
}

function dp_header($pagetitle = "", $args = null) {
    html_header($pagetitle, $args);
    echo "<body id='theme_body'"
        .(@$args["onload"] ? " onload='{$args['onload']}'" : "").">\n";
    html_logobar();
    html_navbar();
}

function dp_footer() {
    echo "
</td></tr>
</table>  <!-- theme_body_table -->
</div>   <!-- theme_body_div -->\n";

    html_footer();
}

function bare_header($pagetitle = "", $is_xlt = true)
{
    global $code_url;
    global $relPath;
    global $css_url;
    global $js_url;

    if($is_xlt)
        $pagetitle = _($pagetitle);
    echo
"<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<title>{$pagetitle}</title>
<link type='text/css' rel='stylesheet' href='{$css_url}/dp.css'>
</head>\n";
}

function bare_footer()
{
    echo "</body></html>";
}

function theme_header($title = null, $sidebar = false, $args = null)
{
    global $is_sidebar;
    $is_sidebar = $sidebar;
    theme($title, "header", $args);
}

function theme_footer()
{
    theme(null, "footer");
}

function forum_link()
{
    global $forums_url;
    return $forums_url;
}

function theme($pagetitle, $hdr_footer, $args = null) {

    global $code_url;
    global $is_sidebar;
    global $User;

    if ($is_sidebar) {
        if ($hdr_footer == "header") {
            html_header($pagetitle, $args);
            echo "
    <body>\n";
            html_logobar();
            html_navbar();

            echo "
    <table class='theme'>
        <tr> 
        <td class='w100'>\n";

        }
        elseif ($hdr_footer == "footer") {

            echo "
        </td>
        <td class='top'>
            <img class='corner' 
                src='$code_url/graphics/r_curve.gif' 
                alt='135 deg round curve'>
        </td>
        <td class='top left w25'>\n"; 

            html_sidebar($pagetitle);

            echo "
        </td></tr>
    </table>\n";

            html_footer();
        }
    }
    else  {   // NOT STATS
        if ($hdr_footer == "header") {
            html_header($pagetitle, $args);
            echo "<body class='nomargin'>\n";
            html_logobar();
            html_navbar();

            echo "
<div class='center'>
    <table class='w100'>
        <tr>
        <td class='left top'>\n";

        } elseif ($hdr_footer == "footer") {
            echo "
        </td></tr>
    </table>  <!-- theme_body_table -->
</div>   <!-- theme_body_div -->\n";

            html_footer();
        }
    }
}

// $args can be css_file, css_data, js_data, js_file

function html_header($pagetitle, $args = null)
{
    global $code_url, $site_abbreviation;
    global $relPath;
    global $css_url;
    global $js_url;

    if(!isset($pagetitle)) 
        $pagetitle = "";
    else
        $pagetitle = ": ".$pagetitle;

echo
"<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<meta name='description' content='Distributed Proofreaders' />
<link rel='shortcut icon' href='$code_url/favicon.ico'>
<title>{$site_abbreviation}{$pagetitle}</title>
<link type='text/css' rel='stylesheet' href='{$css_url}/dp.css'>";

    if($css_file = @$args['css_file']) {
        echo "
<link type='text/css' href='$css_file'>\n";
    }

    if($css_data = @$args['css_data']) {
        echo "
<style type='text/css'>
$css_data
</style\n";
    }

    // Per-page Javascript
    if($js_data = @$args['js_data']) {
        echo "
<script type='text/javascript'>
$js_data
</script>\n";
    }

    if($js_file = @$args['js_file']) {
        echo "
<script type='text/javascript' 
                        src='$js_file' charset='utf-8'></script>\n";
    }

    echo "
</head>\n";
}

function html_logobar()
{
    global $code_url, $site_url, $site_name;
    echo "
    <div id='logobar' class='logobar'>
        <div id='it-logo-left' class='it-logo'>
      <h3>Conserviamo la nostra storia<br/>una pagina per volta</h3>
        </div>
        <div id='it-logo-center' class='it-logo'>
            <img src='$code_url/graphics/dpit-logo.gif' 
                            class='logo' alt='$site_name'>
        </div>
        <div id='it-logo-right' class='it-logo'>
            <h4>xx libri salvati per tutti</h4>
        </div>
    </div>\n";
}


function html_navbar()
// Display the bar containing links to various important points
// within the site (and the login form if the user is not logged in).
{
    global $User;
    global $pm_url;
    global $code_url, $site_abbreviation, $wiki_url;
    global $inbox_url;
    global $registration_url;

    echo "<div class='navbar'>
        <div class='navleft'>
        ".link_to_site()."\n";

    //Code to display login form if not logged in
    if(! $User->IsLoggedIn())
    {

        echo "
        </div>
        <div id='login' class='navright'>
        <form id='login_form' accept-charset='UTF-8' method='post'>
            <span>Username:</span>&nbsp;
            <input class='navbar' type='text' name='userNM' size='10' maxlength='50'>

            <span>Password:</span>&nbsp;
            <input type='password' name='userPW' 
                size='10' maxlength='50'>
            <input type='submit' value='".h(_("Sign In"))."'>
        ".link_to_forums()."
        ".link_to_registration()."
        ".link_to_help()."
        </form>
        </div>
        </div>\n";
        return;
    }

    echo " | ".link_to_activity_hub()."
    <span style='white-space: nowrap;'>[
    "
    
    . ($User->IsProjectManager() 
        ? link_to_projectmgr("PM")
        : "")."\n"
           .link_to_task("proof")."\n"
           .link_to_task("reproof")."\n"
           .link_to_task("mark")."\n"
           .link_to_task("check")."\n"
           .link_to_task("special")."\n";

    echo "]</span>
    ".link_to_my_projects()."
    ".link_to_project_search()."
    </div> <!-- navleft -->\n";

    // right side
    $prompt = ($User->InboxCount() > 0 
        ? sprintf(_("Inbox (%s)"), $User->InboxCount())
        : "Inbox");

    echo "<div class='navright'>
        ".link_to_inbox($prompt)
        .link_to_forums()
        .link_to_stats()
        .link_to_userprefs()
        .link_to_help()
        .link_to_logout()."
        ({$User->Username()})
        </div>
    </div> <!-- navbar -->\n";
        /*
        if(lang_forum())
        {
            $links[] = array('text' => _("Your language forums"),
                              'url' => $forums_url."/".lang_forum());
        }

        if ( !empty($wiki_url) )
        {
            $links[] = array('text' => _("Wiki"), 'url' => $wiki_url);
        }
        */

}

function html_sidebar($pagetitle) 
{
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function maybe_show_language_selector()
{
    global $User;
    global $Context;
    global $code_url;

    $langs = $Context->UserLanguages();
    if(count($langs) < 2) 
        return;

    if($User->Language() == "")
    {
        echo "
        <form name='langform' accept-charset='UTF-8' class='center'
            action='$code_url/tools/setlangcookie.php' method='POST'>
        <div class='center'>
        <select name='lang' onChange='document.langform.submit()'>\n";
        foreach($langs as $lang) {
            echo "<option value='$lang'>"
                .LanguageCodeDescription($lang)."</option>\n";
        }
        echo "
        </select>
        </div>
        <input type='hidden' name='returnto'
                    value='{$_SERVER['REQUEST_URI']}'>
        </form>
        <hr>\n";
    }
}

function show_task_stats( $taskcode )
{
    global $dpdb;
    global $code_url;
    global $is_neighbors;
    global $User, $Context;
    global $pagetasks;

    // Put the all in a table, just so we can put a box around it.
    echo "
    <br>
    <div id='taskstats' class='center light-border'>
        <table>
            <tr>
            <td>\n";

    // Show the site statistics

    echo "
    <div id='task-summary' class='center'>
    <p class='navbar'>".$pagetasks[$taskcode]."</p>

    <h3>" . _("Site Statistics:") . "</h3>

    <div id='goals'>\n";
    // Today's Numbers
    echo "&nbsp;"._("Today's Goal:")." "
        // . number_format($site_stats->curr_day_goal)
        . "<br>\n";
    echo "&nbsp;"._("Today's Total:")." "
        // . number_format($site_stats->curr_day_actual)
        . " (" . strftime("%R") . ")<br><br>\n";

    // Yesterday's Numbers
    echo "&nbsp;"._("Yesterday's Goal:")." "
        // . number_format($site_stats->prev_day_goal)
        . "<br>\n";
    echo "&nbsp;"._("Yesterday's Total:")." "
        // . number_format($site_stats->prev_day_actual)
        . "<br><br>\n";

    // Month's Numbers
    $goal_pct = 0;
       //  ($site_stats->curr_month_goal > 0)
                // ? ($site_stats->curr_month_actual * 100
                    // / $site_stats->curr_month_goal)
                // : 0;
    echo ""
    // echo "&nbsp;".strftime(_("%B's Goal:"))." "
        // . number_format($site_stats->curr_month_goal)
        // . ($site_stats->curr_month_goal
            // ? (" (" . number_format($goalpct, 2) . "%)")
            // : ""
        // . "<br>
        // &nbsp;")
        // .strftime(_("%B's Total:"))." "
        // . number_format($site_stats->curr_month_actual)
        . "<br>
        <br>\n";

    // Number of users
    $num_users = $dpdb->SqlOneValue("SELECT COUNT(*) FROM users" );
    echo "&nbsp;"
        . sprintf( _('%s users'), number_format($num_users) )
        ."<br>\n";

    $num_positive_users = $Context->UsersWithPageCount();
    echo '&nbsp;',
        sprintf(
            _('%s users with at least one %s page'),
            number_format($num_positive_users), $taskcode ),
        "<br>\n";

    echo "
    </div>
    <hr class='hr75'><br>\n";
    // ---------------------------------------------------------------

    if($User->IsLoggedIn())
    {
        // The requestor is a logged-in user.
        // Show the user's personal statistics

        echo "
    <div id='my-stats' class='left'>
    <h3 class='navbar center'>"._("Personal Statistics:")."</h3>
    <div id='personal_stats'>\n";
    echo "<p>"._("Pages Yesterday: ").number_format(0)."</p>\n";
    echo "<p>"._("Pages Today: ").number_format(0)."</p>\n";
    echo "<p>"._("Pages Total: ").number_format(0)."</p>\n";
    echo "
    </div>
    </div>
    </div>

    <div class='center'>
    <p><a href='$code_url/stats/members/mdetail.php&amp;id="
        .$User->Uid()
        ."&amp;taskcode=".$taskcode."'>" . $taskcode . " " 
        .  _("Details...") . "</a>
    </p>
    </div>
    <" . "!-- " . $User->Uid() . " -->\n";
    }

    echo "</td></tr></table>";
    echo "</div>";
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function show_birthdays()
{
    global $dpdb;
    global $site_abbreviation;

    $rows = $dpdb->SqlRows("
        SELECT username,value
        FROM usersettings
        WHERE setting ='birthday_today'
        ORDER BY CAST(value AS UNSIGNED) DESC");

    if (count($rows) == 0)
        return;

    echo "<div id='birthdays' class='center'>" 
        .sprintf(_("Today's %s Birthdays:"),
                        $site_abbreviation) 
        . "</div>
           <div class='center navbar'>\n";

    foreach($rows as $username => $years)
    {
        echo "<h3>$username ($years)</h3><br />";
    }

    echo "</div>
          <br>
          <hr class='hr75'>\n";
}


// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function show_completed_projects($terse = false)
{
    global $dpdb;

    $sql = "
            SELECT 
                COUNT(*) AS projectcount
            FROM projects
            WHERE state = '".PROJ_SUBMIT_PG_POSTED."'";

    $projcount = $dpdb->SqlOneValue($sql);

    echo "
    <div>
        <h3>"._("Completed Projects:")."</h3>
        <p>$projecount</p>
    </div>\n";
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function show_key_help_links()
{
    global $code_url, $forums_url;

    echo "
    <div id='help' class='w90 center'>
        <h3 class='navbar'>
    "._("Key Help Documents:")."
    </h3>
    </div>\n";

    // echo link_to_faq_central();
    // echo link_to_proofing_guidelines();
    // echo link_to_proofing_summary();
    // echo link_to_formatting_guidelines();
    // echo link_to_formatting_summary();
    // echo link_to_tips();
/*
    echo "
        <a href='$code_url/faq/".lang_dir()."faq_central.php'>"
        ._("Frequently Asked Questions")."</a>\n";

    echo "
    <br />
  <a href='$code_url/faq/".lang_dir()."proofreading_guidelines.php'>"
        ._("Proofreading Guidelines")."</a>\n";

    echo "
    <br />
    <a href='$code_url/faq/".lang_dir()."proofing_summary.pdf'>"
        ._("PDF Summary")."</a>)
    <br>\n";

    echo "
    <br />
    <a href='$code_url/faq/".lang_dir()."document.php'>"
                                ._("Formatting Guidelines")."</a>
     <a href='$code_url/faq/".lang_dir()."formatting_summary.pdf'>"
        ._("PDF Summary")."</a>)\n";
    echo "
    <br />
    <a href='$forums_url/viewtopic.php?t=2368'>"
        ._("Tips and How-To's")."</a>\n";

    echo "
    <br />
    <a href='$code_url/tasks.php'>"._("Support Request")."</a>\n";
*/
}



// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

function echo_login_form()
{
    echo "
    <div id='login' class='navright'>
        <form id='login_form' accept-charset='UTF-8' method='post'>
            <span>"._("Username:")."</span
            >&nbsp;
            <input class='navbar' type='text'
                name='userNM' size='10' maxlength='50'>

            <span>" . _("Password:") . "</span
            >&nbsp;
            <input type='password' name='userPW'
                size='10' maxlength='50'>"
            ."&nbsp;"
            ."<input type='submit' value='". _("Sign In") ."'>
        </form>\n";

    echo link_to_registration();
        
    echo link_to_help();

    echo "</div>\n";
}


function html_footer() 
{
    global $site_name;

    // $mtime = explode(" ",microtime());
    // $endtime = $mtime[1] + $mtime[0];
    // $totaltime = number_format($endtime - $starttime, 2);

    echo "
    <div class='footerbar'>
    ". _("Copyright")." $site_name
    ("._("Page Build Time").": ".get_timer().") 
    </div>
    </body>
</html>";
}

// vim: sw=4 ts=4 expandtab
?>
